<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>

<html>
<head>
<title>通过JSP打开数据表</title>
</head>
<body>
<h1>
<%
Statement stmt = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver"); ////驱动程序名
String url = "jdbc:mysql://localhost:3306/java63class"; //数据库名
String username = "root"; //数据库用户名
String password = "zcxzcx19"; //数据库用户密码
Connection conn = DriverManager.getConnection(url, username, password); //连接状态
		try {
			if (conn != null) {
				out.print("数据库连接成功！");
				out.print("<br />");
				String sql = "SELECT * FROM s_student"; //查询语句
				stmt = conn.createStatement();
				rs = stmt.executeQuery(sql);
				out.print("查询结果：");
				out.print("<br />");
				out.print("<br />");
				while (rs.next()) {
					out.println("名字："+rs.getString("sname") + "   &nbsp  性别：" + rs.getString("sex") + "  &nbsp 出生日期：" + rs.getString("birthday") + "  &nbsp qq号：" + rs.getInt("qq") + "  &nbsp 微信号：" + rs.getString("wechat")); //将查询结果输出  
					out.print("<br />");
				}
			} else {
				out.print("连接失败！");
			}
		} catch (Exception e) {
			out.print("数据库连接异常！");
		}
finally{
	rs.close();
	stmt.close();
	conn.close();
}
	%></h1>
</body>
</html>